package com.yklx.youke.admin.controller;

import com.yklx.youke.service.BookingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/admin")
@CrossOrigin(origins = "*", maxAge = 3600)
public class AdminBookingController {

    @Autowired
    private BookingService bookingService;

    /**
     * 获取所有预约（管理端）
     */
    @GetMapping("/bookings")
    public ResponseEntity<List<Map<String, Object>>> getAllBookings(
            @RequestParam(required = false) String status,
            @RequestParam(required = false) String dateRange,
            @RequestParam(required = false) Boolean includePast) {
        try {
            // 这是管理端的获取所有预约接口
            List<Map<String, Object>> bookings = bookingService.getAllBookings(status, dateRange, includePast);
            return ResponseEntity.ok(bookings);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.badRequest().build(); // 简化错误处理
        }
    }
}